package com.yndsoft.jc.supplier.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.yndsoft.jc.supplier.widget.ZoomImageView;

import java.util.List;

public class PreviewPicturePagerAdapter extends PagerAdapter {

    private Context context;
    private List<String> imgList;
    private ImageView[] imageViews;

    public PreviewPicturePagerAdapter(Context context, List<String> imgList, ImageView[] imageViews) {
        this.context = context;
        this.imgList = imgList;
        this.imageViews = imageViews;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ZoomImageView imageView = new ZoomImageView(context);
        Glide.with(context).load(imgList.get(position)).into(imageView);
        container.addView(imageView);
        imageViews[position] = imageView;
        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(imageViews[position]);
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public int getCount() {
        return imgList.size();
    }
}
